// Facade: 问卷系统统一入口
import { getQuestionnaire as getSchema, getAssessConfig } from './schema-loader.js'
import { initializeVisibilityFacts } from './facts-manager.js'
import { visibilityEngine, getValidQuestionIds } from './visibility-engine.js'
import { getCompressor, assessKeys } from './compressor.js'
import { generateTags, getTagDisplayName, getTagEnglishName, getTagConfig } from './tag-manager.js'
import { getAdvices, getAdvicesFromAssessmentResults } from './advice-engine.js'
import { saveResults } from './save-results.js'
import { getAssessmentSetManager } from './questionnaire-set.js'
import { toResult } from './ques-judgers.js'
import { getKeyword } from './keyword-handler.js'
import { getHealthtestConfig } from './schema-loader.js'

/**
 * 获取问卷定义
 * @param {string} type - 问卷类型 ('screening', 'assessment', 'healthtest')
 * @param {string} id - 问卷ID (assessment 子问卷需要)
 * @returns {Object} 问卷定义
 */
export const getQuestionnaire = getSchema;

/**
 * 获取可见题目ID
 * @param {string} quesName - 问卷名称
 * @param {Array} ids - 题目ID数组
 * @param {Array} filters - 过滤条件数组
 * @param {Array} answers - 当前答案数组
 * @param {Object} questions - 题目对象
 * @returns {Array} 可见题目ID数组
 */
export const getVisibleQuestionIds = (quesName, ids, filters, answers, questions) => {
  return visibilityEngine.getValidQuestionIds(ids, filters, answers, questions);
};

/**
 * 初始化问卷系统
 */
export const initialize = initializeVisibilityFacts;
export const initializeQuestionnaireSystem = initializeVisibilityFacts;

/**
 * 提交答案（暂未实现，继续使用现有页面逻辑）
 * @param {Object} params - 参数对象
 * @returns {Promise<Object>} 结果对象
 */
export const submitAnswers = async (params) => {
  throw new Error('submitAnswers not yet implemented; continue using existing page handlers for now.');
}

// 导出其他接口
export {
  saveResults,
  getCompressor,
  generateTags,
  getAdvices,
  getAdvicesFromAssessmentResults,
  getTagDisplayName,
  getTagEnglishName,
  getTagConfig,
  getAssessmentSetManager,
  createQuesJudger,
  createDefaultQuesJudger,
  QuesJudger,
  QuestionLogicEngine,
  toResult,
  getValidQuestionIds,
  getAssessConfig,
  getHealthtestConfig,
  assessKeys,
  getKeyword,
}


